#include <iostream>
using namespace std;
const int N = 100010;

int p[N];//N的父亲节点 当p[n] = n时为祖宗节点
int find(int x)
{
    if (p[x] != x)
    {
       return  p[x] = find(p[x]);
    }
    return x;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        p[i] = i;
    }
    while (m--)
    {
        int a, b;
        char op[2];
        scanf("%s%d %d", op, &a, &b);
        if (op[0] == 'Q')
        {
            if (find(a) == find(b))
            {
                printf("Yes\n");
            }
            else
            {
                printf("No\n");
            }
        }
        else
        {
            p[find(b)] = find(a);
        }
    }
        return 0;
}